#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void center(int *nums,char *s,int left ,int right)
{
    while(left >= 0 && right < strlen(s) && s[left] == s[right])
    {
        left--;
        right++;
    }
    nums[0] = left + 1;
    nums[1] = right - 1;
}


char* longestPalindrome(char* s) 
{
    int nums[2] = {0} ;
   
    int start = 0;
    int end = 0;
    for(int i = 0;i < strlen(s);i++)
    {
        center(nums,s,i,i);
        if((nums[1] - nums[0]) > (end - start))
        {
            start = nums[0];
            end = nums[1];
        }
    }
     char *ptr = (char *)malloc(sizeof(char)*(end - start + 1));
     int n = 0;
     for(int i = start;i <= end;i++)
     {
        ptr[n++] = s[i];
     }

    return ptr;
}


int main()
{
    char s[] = "ababc";
    char *p = longestPalindrome(s);
    // for(int i = 0;i < strlen(p);i++)
        printf("%s\n",p);

    return 0;
}